/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.control;

import DBMS.DataBaseManager;
import clases.Periodo;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author charles
 */
public class Modificar extends DispatchAction {
    
    public ActionForward update(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
         Periodo p = (Periodo) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        boolean modificado = dbms.modificarPeriodo(p);
        if (modificado) {
            p.setMensaje("Periodo modificado exitosamente");
            return mapping.findForward("success");
        } else {
            p.setMensaje("Problemas al modificar el periodo");
            return mapping.findForward("success");
        }
    }
    
    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DataBaseManager dbms = DataBaseManager.getInstance();
        Periodo p = new Periodo();
        List list = dbms.consultarPeriodo(p);
        p = (list != null && !list.isEmpty() ? (Periodo) list.get(0) : null);
        if(p == null){
            return mapping.findForward("failure");
        }else{
        request.setAttribute("Periodo", p);
            return mapping.findForward("page");
            
        }
    }
}